//
//  HYHomeTableViewCell.swift
//  HYYWeibo
//
//  Created by HY-Mac on 16/7/16.
//  Copyright © 2016年 HY-Mac. All rights reserved.
//

import UIKit
import SDWebImage

class HomeTableViewCell: UITableViewCell {
    @IBOutlet weak var iconImageView: UIImageView!

    @IBOutlet weak var vipImageView: UIImageView!
    
    @IBOutlet weak var verifiedImageView: UIImageView!
    
    @IBOutlet weak var nameLabel: UILabel!
    
    @IBOutlet weak var sourceLabel: UILabel!
    @IBOutlet weak var timeLabel: UILabel!
    
    @IBOutlet weak var contentLabel: UILabel!
    
    var status: Statuses?{
        didSet{
            
            iconImageView.sd_setImageWithURL(status?.user?.icon_URL)
            
            nameLabel.text = status?.user?.screen_name
            
            sourceLabel.text = status?.source
            
            if let image = status?.user?.verified_image{
                verifiedImageView.image = image
            }
            
            //timeLabel.text = status?.created_at
            
            if let rank = status?.user?.mbrank
            {
                vipImageView.image = nil
                nameLabel.textColor = UIColor.blackColor()
                if rank >= 1 && rank <= 6
                {
                    vipImageView.image = status?.user?.mbrankImage
                    nameLabel.textColor = UIColor.orangeColor()
                } 
            }
            //微博来源
            //"source": <a href="http://app.weibo.com/t/feed/c66T5g" rel="nofollow">Android客户端</a>
            
            sourceLabel.text = status?.source_readableStr
            
            /**
             刚刚(一分钟内)
             X分钟前(一小时内)
             X小时前(当天)
             
             昨天 HH:mm(昨天)
             
             MM-dd HH:mm(一年内)
             yyyy-MM-dd HH:mm(更早期)
             */
            // "Sun Dec 06 11:10:41 +0800 2015"
            // 设置时间
          /*  if let timeStr = status?.created_at{
                
                //timeStr = "Sun Jul 15 11:10:41 +0800 2016"
                let createDate = NSDate.createWeiboDateFromString(timeStr, formatStr: "EE MM dd HH:mm:ss Z yyyy")

                
                timeLabel?.text = NSDate().createWeiboTimeString(createDate)
            }
            */
            timeLabel?.text = status?.createTimeStr
            //微博内容

            
            contentLabel.text = status?.text
        }
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
        contentLabel.preferredMaxLayoutWidth = UIScreen.mainScreen().bounds.width - 10 * 2
        iconImageView.layer.cornerRadius = 30
        
    }


}
